﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
namespace iSun.WebApp.Extend.Common
{
    public class Staple
    {
        #region 对齐字符串
        /// <summary>
        /// 对齐字符串
        /// </summary>
        /// <param name="src">字符串</param>
        /// <param name="sLen">对齐度</param>
        /// <returns></returns>
        public static string PadString(string src, int sLen)
        {
            if (src.Length >= sLen)
                return "<span title=\"" + src.Replace("\"", "“") + "\">" + src.Substring(0, sLen) + "...</span>";
            else
                return "<span title=\"" + src.Replace("\"", "“") + "\">" + src + "</span>";
        }

        /// <summary>
        /// 对齐字符串
        /// </summary>
        /// <param name="src">字符串</param>
        /// <param name="tipsrc">提示字符串</param>
        /// <param name="sLen">对齐度</param>
        /// <returns></returns>
        public static string PadString(string src, string tipsrc, int sLen)
        {
            if (src.Length >= sLen)
                return "<span title=\"" + tipsrc.Replace("\"", "“") + "\">" + src.Substring(0, sLen) + "...</span>";
            else
                return "<span title=\"" + tipsrc.Replace("\"", "“") + "\">" + src + "</span>";
        }

        /// <summary>
        /// 对齐字符串
        /// </summary>
        /// <param name="src">字符串</param>
        /// <param name="sLen">对齐度</param>
        /// <param name="sta">是否带tip提示</param>
        /// <returns></returns>
        public static string PadString(string src, int sLen, bool sta)
        {
            if (sta) return PadString(src, sLen);
            if (src.Length >= sLen)
                return src.Substring(0, sLen) + "...";
            else
                return src;
        }
        #endregion

        #region 解码
        /// <summary>
        /// 解码
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string Decode(string str)
        {
            if (str == null) return "";
            str = str.Replace("%1", "<");
            str = str.Replace("%2", ">");
            str = str.Replace("%3", "\"");
            str = str.Replace("%4", "&");
            str = str.Replace("%5", "%");
            str = str.Replace("%6", " ");
            str = str.Replace("%7", ",");
            str = str.Replace("%8", "'");

            return str;
        }

        /// <summary>
        /// 编码
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string Coding(string str)
        {
            if (str == null) return "";
            str = str.Replace("'", "%8");
            str = str.Replace(",", "%7");
            str = str.Replace(" ", "%6");
            str = str.Replace("%", "%5");
            str = str.Replace("&", "%4");
            str = str.Replace("\"", "%3");
            str = str.Replace(">", "%2");
            str = str.Replace("<", "%1");

            return str;
        }
        #endregion


        /// <summary>
        /// 显示姓名
        /// </summary>
        /// <param name="us"></param>
        /// <returns></returns>
        public static string ShowName(string Name)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<SPAN title='");
            sb.Append(Name);
            sb.Append("'");
            sb.Append(">");
            sb.Append(Name);
            sb.Append("</SPAN>");

            return sb.ToString();
        }

   

        

        
    }
}